﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.util {
    import Engine.Managers.*;
    import Events.*;
    import Transactions.*;
    import __AS3__.vec.*;
    import flash.system.*;
    import Engine.*;
    import com.adobe.crypto.*;
    import flash.external.*;

    public class GameUtil extends Utilities {

        private static const SERVER_UID_PREFIX:String = "i";

        protected static var seed:Number = 0;

        public static function synchronizedDateToNumber(_arg1:String):Number{
            var _local2:int = ((Global.gameSettings.getInt("globalServerUTCOffsetHours") * 3600) * 1000);
            return ((Utilities.dateToNumber(_arg1, true) + _local2));
        }
        public static function formatMinutesSeconds(_arg1:Number):String{
            var _local2:int = int((_arg1 % 60));
            var _local3:int = int(((_arg1 - _local2) / 60));
            var _local4:int = int((_local3 % 60));
            var _local5:int = int(((_local3 - _local4) / 60));
            var _local6:String = ((_local5)>0) ? (_local5 + ":") : "";
            _local6 = (_local6 + ((((_local4)>=10) ? "" : "0" + _local4) + ":"));
            _local6 = (_local6 + (((_local2)>=10) ? "" : "0" + _local2));
            return (_local6);
        }
        public static function redirectHomeVersionMismatch(_arg1:GenericPopupEvent=null):void{
            if (Utilities.isFullScreen()){
                Utilities.setFullScreen(false);
            };
            reloadApp(true, "enhance");
        }
        public static function redirectHome(_arg1:GenericPopupEvent=null):void{
            refreshUserState(null, true);
        }
        public static function refreshUserState(_arg1:GenericPopupEvent=null, _arg2:Boolean=false):void{
            var _local3:TRefreshUser;
            if (TRefreshUser.canCall(_arg2)){
                _local3 = new TRefreshUser(GlobalEngine.socialNetwork.getLoggedInUser().name, _arg2);
                GameTransactionManager.addTransaction(_local3, true, true);
            } else {
                reloadApp(_arg2, "error");
            };
        }
        public static function reloadApp(_arg1:Boolean=false, _arg2:String=""):void{
            if (_arg1){
                StatsManager.count("refresh", "app", _arg2);
                StatsManager.sendStats(true);
            };
            ExternalInterface.call("ZYFrameManager.reloadApp");
        }
        public static function formatServerUid(_arg1:String):String{
            var _local2:String = _arg1;
            if (((((_arg1) && (_arg1.length))) && ((_arg1.charAt(0) == SERVER_UID_PREFIX)))){
                _local2 = _arg1.slice(1);
            };
            return (_local2);
        }
        public static function vectorToArray(_arg1:Object):Array{
            var _local4:Object;
            var _local2:Vector.<Object> = Vector.<Object>(_arg1);
            var _local3:Array = [];
            for each (_local4 in _local2) {
                _local3.push(_local4);
            };
            return (_local3);
        }
        public static function srand(_arg1:Number):void{
            GameUtil.seed = _arg1;
        }
        public static function rand(_arg1:int, _arg2:int):int{
            var _local3:String = Global.player.uid;
            var _local4:String = (((("FOR_GR8_JUSTICE" + "::") + _local3) + "::") + GameUtil.seed);
            var _local5:int = ((_arg2 - _arg1) + 1);
            var _local6:String = ("0x" + MD5.hash(_local4).substring(0, 8));
            var _local7:Number = Number(_local6);
            var _local8:int = (_local7 % _local5);
            var _local9:int = (_local8 + _arg1);
            GameUtil.seed = (GameUtil.seed + 1);
            return (_local9);
        }
        public static function replaceCharacterStrings(_arg1:String, _arg2:String, _arg3:String=""):String{
            var _local6:String;
            var _local7:String;
            var _local4:String = _arg1;
            var _local5:int;
            if (_arg2.length == 0){
                return (_local4);
            };
            if (_arg2.length > _arg1.length){
                return (_local4);
            };
            _local5 = _local4.indexOf(_arg2);
            while (_local5 > -1) {
                _local6 = _local4.substr(0, _local5);
                _local7 = _local4.substr((_local5 + 1), (_local4.length - _local5));
                _local4 = ((_local6 + _arg3) + _local7);
                _local5 = _local4.indexOf(_arg2);
            };
            return (_local4);
        }
        public static function trimBadStatsCharacters(_arg1:String):String{
            var _local5:String;
            var _local2:String = Global.gameSettings.getString("inavlidNameCharacters");
            var _local3:String = _arg1;
            _local3 = replaceCharacterStrings(_local3, " ", "_");
            _local3 = replaceCharacterStrings(_local3, "-", "_");
            var _local4:int;
            while (_local4 < _local2.length) {
                _local5 = _local2.substr(_local4, 1);
                _local3 = replaceCharacterStrings(_local3, _local5);
                _local4++;
            };
            _local3 = replaceCharacterStrings(_local3, "'");
            _local3 = replaceCharacterStrings(_local3, "!");
            _local3 = replaceCharacterStrings(_local3, ",");
            return (_local3.toLowerCase());
        }
        public static function logMachineInfo():Array{
            var _local1:String = Capabilities.version;
            var _local2:String = Capabilities.language;
            var _local3:String = Capabilities.os;
            var _local4:String = ((Capabilities.screenResolutionX + " x ") + Capabilities.screenResolutionY);
            var _local5 = ((System.totalMemory / (0x0400 * 0x0400)).toFixed(3) + " MB ");
            var _local6:Array = new Array(_local1, _local2, _local3, _local4, _local5);
            return (_local6);
        }
        public static function countObjectLength(_arg1:Object):int{
            var _local3:*;
            var _local2:int;
            for (_local3 in _arg1) {
                _local2++;
            };
            return (_local2);
        }

    }
}//package Classes.util 
